'use strict';
/* Controllers */
app.controller('fundListCtrl', ['$scope', '$http', '$state', 'apiService', '$cookieStore', '$timeout', '$rootScope','toaster', function ($scope, $http, $state, apiService, $cookieStore, $timeout, $rootScope,toaster) {
    $scope.search_obj = {
        payType:'cz',
        startTime:moment('2000-01-01 00:00').format('YYYY-MM-DD HH:mm'),
        endTime:moment().format('YYYY-MM-DD HH:mm'),
        pageSize: 10
    };

    $scope.paginationConf = {
        currentPage: 1,
        totalItems: 66,
        itemsPerPage: $scope.search_obj['pageSize'],
        perPageOptions: [10, 20, 30, 40, 50],
        onChange: function () {
            $scope.pageData=[];
            $scope.search_obj['rows'] = $scope.paginationConf.currentPage;

            var post_obj={
                'cz':{
                    modelName:'recharge',
                    apiName:'QueryrechargeDBtime',
                },
                'zz':{
                    modelName:'transferAccounts',
                    apiName:'QueryTransferAccountsTime',
                },
                'tx':{
                    modelName:'withdrawDeposit',
                    apiName:'QueryWithdrawDepositByTime',
                },
                'jj':{
                    modelName:'bonus',
                    apiName:'QuerybonusDBtime',
                },
                'hk':{
                    modelName:'financeAccount',
                    apiName:'QueryfinanceAccountDBtime'
                }
            }

            if($scope.search_obj.startTime){
                $scope.search_obj.startTime=moment($scope.search_obj.startTime).format('YYYY-MM-DD HH:mm');
            }

            if($scope.search_obj.endTime){
                $scope.search_obj.endTime=moment($scope.search_obj.endTime).format('YYYY-MM-DD HH:mm');
            }

            // 获取交易记录列表
            apiService.post({
                modelName: post_obj[$scope.search_obj.payType]['modelName'],
                apiName: post_obj[$scope.search_obj.payType]['apiName']
            }, $scope.search_obj, function (data) {
                if (data.code == 200) {
                    $scope.pageData = data['data']['list'];
                    $scope.paginationConf.totalItems = data['data']['total']? data['data']['total']:0;
                } else {
                    toaster.pop('error', '提示', data['msc']);
                }
            }, function (err) {
                toaster.pop('error', '提示', '服务器出小差咯...');
            });
        }
    };
    

    $scope.searchFun = function () {
        $scope.paginationConf.onChange();
    }

    $scope.$watch('search_obj.payType',function(){
        $scope.paginationConf.onChange();
    });


}]);